package com.jiazhong.mingxing.boot.boot09.config;

import com.jiazhong.mingxing.boot.boot09.interceptor.FirstInterceptor;
import com.jiazhong.mingxing.boot.boot09.interceptor.SecondInterceptor;
import com.jiazhong.mingxing.boot.boot09.interceptor.ThirdInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringMVCConfig implements WebMvcConfigurer {
    @Resource
    private FirstInterceptor firstInterceptor;
    @Resource
    private SecondInterceptor secondInterceptor;
    @Resource
    private ThirdInterceptor thirdInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册了某个拦截器  /first/a/b
        registry.addInterceptor(firstInterceptor)
                .addPathPatterns("/**")  //对于那些请求拦截
                .excludePathPatterns("/first/a", "/second/b");   // 对于那些请求不拦截
        registry.addInterceptor(thirdInterceptor).addPathPatterns("/second/a");
        registry.addInterceptor(secondInterceptor).addPathPatterns("/second/**");
    }
}
